<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/transitional.dtd">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>当前区划下级部门</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<script type="text/javascript" src="js/lib/jquery-1.9.1.min.js"></script>
		<link rel="stylesheet" type="text/css" href="css/currentarea.css">
		<script type="text/javascript">
		$(function(){
			var value;
			var firstCode;
			var param;
			$('div').delegate('.span-item','click',function(){
				value = $(this).attr('areacode')
				if(firstCode!=value){
					if(param==value){
						param='';
						return false;
					}
					param = value;
					$.getJSON('com.future.servlet/PickAreaServlet',{code : value,flag:'aa'},function(data) {
						var temphtml = "<table><tr>"
						$.each(data.areaList,function(i, item) {
							if(i==0){
								var title = item.area; 
								if($('.title').text().indexOf(title)<0){
									title = $('.title').text() +title;
									$('.title').css('font-size',($('.title').css('font-size').substring(0,2)-7)+'px');
									$('.title').css('letter-spacing',$('.title').css('letter-spacing').substring(0,2)-10+'px');
									$('.title').text(item.fullname);
									$('.hidden-code').text(item.code);
									firstCode = item.code;
								}
								$('.area-fill').html('');
							}
							if(((i%4)==0)&&i!==0){
								temphtml = temphtml+"</tr><tr>"
							}
							var span;
							if(${userBo.user.departmentId}==1){
								if(item.surveySum>0){
									span = '<span class="span-item" areacode="' + item.code +
									'"> ' + item.area+'('+item.surveySum+')' + '</span>';
								}else{
									span = '<span class="novalue" areacode="' + item.code +
									'"> ' + item.area+'('+item.surveySum+')' + '</span>';
								}
							} else if(${userBo.user.departmentId}==34||${userBo.user.departmentId}==35){
								if(item.townSum>0){
									span = '<span class="span-item" areacode="' + item.code +
									'"> ' + item.area+'('+item.townSum+')' + '</span>';
								}else{
									span = '<span class="novalue" areacode="' + item.code +
									'"> ' + item.area+'('+item.townSum+')' + '</span>';
								}
							} else{
								if(item.deparSum>0){
									span = '<span class="span-item" areacode="' + item.code +
									'"> ' + item.area+'('+item.deparSum+')' + '</span>';
								}else{
									span = '<span class="novalue" areacode="' + item.code +
									'"> ' + item.area+'('+item.deparSum+')' + '</span>';
								}
							}
							temphtml = temphtml + '<td>'+span+'</td>';
						});
						temphtml = temphtml + '</tr></table>';
						$('.area-fill').append(temphtml);
					});
				}else {
					$(this).css('background-color','red');
					$(this).css('color','white');
				}
			});
					
			$('.submit').on('click',function(){
				if(value!=undefined){
		  	 			window.showModalDialog("com.future.servlet/LoginServlet?flag=currentarea&code="+value,"aa","dialogWidth=1000%;dialogHeight=700%; center=yes;dialogTop=100%;dialogLeft=150%;");
		  	 		}else{
						alert("请选择要查看的区域！");
				}
			});
			
			$('.presubmit').on('click',function(){
				var temp =$('.hidden-code').text();
				var provinceFlag = new RegExp("^[0-9]{2}[0]{7}$");
				var cityFlag = new RegExp("^[0-9]{4}[0]{5}$");
				var countyFlag = new RegExp("^[0-9]{6}[0]{3}$");
			    var templogincode = ${fn:substring(userBo.user.username, 0, 9)};
				if (provinceFlag.test(temp)) {
					if((templogincode==(temp.substring(0,2)+'0000000'))==true){
						if(confirm("不能查看当前登录用户上级\n是否关闭当前窗口？")){
							window.close();
						} else {
							return false;
						}
					}
					temp = temp;
				} else if (cityFlag.test(temp)) {
					if((templogincode==(temp.substring(0,4)+'00000'))==true){
						if(confirm("不能查看当前登录用户上级\n是否关闭当前窗口？")){
							window.close();
						} else {
							return false;
						}
					}
					temp = temp.substring(0,2)+'0000000';
				} else if (countyFlag.test(temp)) {
					if((templogincode==(temp.substring(0,6)+'000'))==true){
						if(confirm("不能查看当前登录用户上级\n是否关闭当前窗口？")){
							window.close();
						} else {
							return false;
						}
					}
					temp = temp.substring(0,4)+'00000';
				} else {
					if(templogincode==temp){
						if(confirm("不能查看当前登录用户上级\n是否关闭当前窗口？")){
							window.close();
						} else {
							return false;
						}
					} else {
						if(confirm("不能查看当前登录用户上级\n是否关闭当前窗口？")){
							window.close();
						} 
					}
					temp = temp.substring(0,6)+'000';
				}
				$.getJSON('com.future.servlet/PickAreaServlet',{code : temp,flag:'aa'},function(data) {
					var temphtml = "<table><tr>"
					$.each(data.areaList,function(i, item) {
						if(i==0){
							var title = item.area; 
							if(parseInt($('.title').css('font-size').substring(0,2))<40){
								$('.title').css('font-size',(parseInt($('.title').css('font-size').substring(0,2))+7)+'px');
							}
							if(parseInt($('.title').css('letter-spacing').substring(0,2))<25){
								$('.title').css('letter-spacing',parseInt($('.title').css('letter-spacing').substring(0,2))+10+'px');
							}
							$('.title').text(item.fullname);
							$('.hidden-code').text(item.code);
							firstCode = item.code;
							$('.area-fill').html('');
						}
						if(((i%4)==0)&&i!==0){
							temphtml = temphtml+"</tr><tr>"
						}
						var span;
						if(${userBo.user.departmentId}==1){
							if(item.surveySum>0){
								span = '<span class="span-item" areacode="' + item.code +
								'"> ' + item.area+'('+item.surveySum+')' + '</span>';
							}else{
								span = '<span class="novalue" areacode="' + item.code +
								'"> ' + item.area+'('+item.surveySum+')' + '</span>';
							}
						} else if(${userBo.user.departmentId}==34||${userBo.user.departmentId}==35){
							if(item.townSum>0){
								span = '<span class="span-item" areacode="' + item.code +
								'"> ' + item.area+'('+item.townSum+')' + '</span>';
							}else{
								span = '<span class="novalue" areacode="' + item.code +
								'"> ' + item.area+'('+item.townSum+')' + '</span>';
							}
						} else{
							if(item.deparSum>0){
								span = '<span class="span-item" areacode="' + item.code +
								'"> ' + item.area+'('+item.deparSum+')' + '</span>';
							}else{
								span = '<span class="novalue" areacode="' + item.code +
								'"> ' + item.area+'('+item.deparSum+')' + '</span>';
							}
						}
						temphtml = temphtml + '<td>'+span+'</td>';
					});
					temphtml = temphtml + '</tr></table>';
					$('.area-fill').append(temphtml);
				});
			});
		});
		</script>
	</head>
	<body>
		<div class="title-container">
			<div class="title">
				${areaBo.areaList[0].fullname }
			</div>
			<div class="hidden-code">${areaBo.areaList[0].code }</div>
		<c:set var="areaList" value="${areaBo.areaList}"></c:set>
		<div class="container">
			<div class="area-fill">
			<c:if test="${!empty areaList}">
				<table>
					<tr>
						<c:forEach var="areaobj" items="${areaList}" varStatus="status">
							<c:if test="${(status.count-1)%4==0&& status.count!=1}">
								</tr><tr>
							</c:if> 
							<td>
								<c:choose>
									<c:when test="${sessionScope.userBo.user.departmentId==1 }">
										<c:if test="${areaobj.surveySum>0 }">
											<span class="span-item" areacode="${areaobj.code }">${areaobj.area }(${areaobj.surveySum })</span>
										</c:if>
										<c:if test="${areaobj.surveySum<=0 }">
											<span class="novalue" areacode="${areaobj.code }">${areaobj.area }(${areaobj.surveySum })</span>
										</c:if>
									</c:when>
									<c:when test="${sessionScope.userBo.user.departmentId ==35||sessionScope.userBo.user.departmentId ==34}">
										<c:if test="${areaobj.townSum>0 }">
											<span class="span-item" areacode="${areaobj.code }">${areaobj.area }(${areaobj.townSum })</span>
										</c:if>
										<c:if test="${areaobj.townSum<=0 }">
											<span class="novalue" areacode="${areaobj.code }">${areaobj.area }(${areaobj.townSum })</span>
										</c:if>
									</c:when>
									<c:otherwise>
										<c:if test="${areaobj.deparSum>0 }">
											<span class="span-item" areacode="${areaobj.code }">${areaobj.area }(${areaobj.deparSum })</span>
										</c:if>
										<c:if test="${areaobj.deparSum<=0 }">
											<span class="novalue" areacode="${areaobj.code }">${areaobj.area }(${areaobj.deparSum })</span>
										</c:if>
									</c:otherwise>
								</c:choose>
							</td>
						</c:forEach>
					</tr>
				</table>
			</c:if>	
			</div>
			<div class="button-container">
				<input type="button" class="submit" value="查看">
				<input type="button" class="presubmit" value="返回上级">
			</div>	
		</div>
	</body>
</html>
